-
Notifications
You must be signed in to change notification settings - Fork 3.2k
REST API: Convert empty properties arrays to objects for valid JSON schema #8608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
REST API: Convert empty properties arrays to objects for valid JSON schema #8608
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
9308318 to
b7fad5c
Compare
felixarntz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@himanshupathak95 Thank you for the PR!
The sanitizer function looks great. I think there's one problem to figure out though regarding when to call it.
b7fad5c to
d4af322
Compare
3b5b3b2 to
bb75e9a
Compare
…to handle additional parameters
…o an object in schema
…changed in schema
…ies field is not affected
… request handling
…te logic into WP_REST_Server
bb75e9a to
f57bee4
Compare
Trac ticket: https://core.trac.wordpress.org/ticket/63186
This PR addresses the issue where empty
propertiesarrays in REST API JSON schemas are output as[]instead of{}.According to JSON Schema specifications, the
propertiesfield must always be an object. However, when a REST API schema in PHP uses'properties' => array(), it gets JSON-encoded as"properties": [], which is an invalid JSON schema.This PR adds a sanitization function that recursively processes REST API schema data and converts any empty
propertiesarrays to empty objects (usingstdClass), ensuring valid JSON schema output. The fix is minimal and targeted, applied via a filter at the appropriate stage of REST API response processing.